# 1导包
from api.add_cart import Add_Cart_API
from api.lite_login import LiteLoginAPI
# 创建测试类
class TestAddcartAPI:
    TOKEN=None#全局变量
    def setup_method(self):
        self.add_api = Add_Cart_API()#实例化加购接口
        self.login_api = LiteLoginAPI()#实例化登录接口
        res=self.login_api.login(test_data={"username":"user123",
                                            "password":"user123"})
        TestAddcartAPI.TOKEN=res.json()["data"]["token"]

    def teardown_method(self):
        pass
    # 编写测试用例
    # 加购成功
    def test01_success(self):
        cart_data={"goodsId":1181000,"number":1,"productId":2}
        res=self.add_api.add_cart(test_data=cart_data,token=TestAddcartAPI.TOKEN)
        assert res.json().get("errno") == 0
        assert res.json().get("errmsg") == "成功"
        assert res.json().get("errno") == 0

#         加购失败(goodsid不存在)
    def test02_fail_goodsid_not_exist(self):
        cart_data={"goodsId":-1,"number":1,"productId":2}
        res=self.add_api. add_cart(test_data=cart_data,token=TestAddcartAPI.TOKEN)